﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CMSService
{
    /// <summary>
    /// 投票
    /// </summary>
    public class VotingService : ICMS.IVoting
    {
        DavidDB.ADO.DBManager db = null;
        private VotingService()
        {
            db = new DavidDB.ADO.DBManager();
        }
        public VotingService(DavidDB.ADO.DBManager db)
        {
            this.db = db;
        }






        /// <summary>
        /// 获取一个网站投票
        /// </summary>
        /// <param name="id">投票编号</param>
        /// <returns>网站投票，如果没有，返回Null</returns>
        public CMSModel.Voting GetModel(int id)
        {
            CMSModel.Voting returnValue = new CMSModel.Voting();
            returnValue.Id = id;
            returnValue = db.GetModel(returnValue);
            return returnValue;
        }
        /// <summary>
        /// 删除一个网站投票
        /// </summary>
        /// <param name="id">投票编号</param>
        /// <returns>成功删除，返回0，没有当前投票，返回-1</returns>
        public int Delete(int id)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            CMSModel.Voting model = new CMSModel.Voting();
            model.Id = id;
            db.Delete(model);
            return returnValue;
        }
        /// <summary>
        /// 增加一个网站投票
        /// </summary>
        /// <param name="announcement">网站投票实体</param>
        /// <returns>增加成功，返回0</returns>
        public int Insert(CMSModel.Voting voting)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Insert(voting);
            return returnValue;
        }
        /// <summary>
        /// 编辑一个投票
        /// </summary>
        /// <param name="announcement">编辑完成的投票</param>
        /// <returns>编辑成功，返回0</returns>
        public int Edit(CMSModel.Voting voting)
        {
            int returnValue = (int)CMSModel.DBOperatorStatus.Success;
            db.Edit(voting);
            return returnValue;
        }
        /// <summary>
        /// 到底最新的count条记录
        /// </summary>
        /// <param name="count">查询条数</param>
        /// <returns>如果记录足够多，返回count条，否则，返回所有记录</returns>
        public List<CMSModel.Voting> GetList(int count)
        {
            List<CMSModel.Voting> lists = new List<CMSModel.Voting>();
            var query = db.GetTopList(count, new CMSModel.Voting());
            foreach (CMSModel.Voting model in query)
            {
                lists.Add(model);
            }
            return lists;
        }
    }
}
